<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="showStore">显示创库的内容</button>
        <!-- <h1>{{this.$store.state.counter}}</h1> -->
        <h1>{{counter}}</h1>
        <h1>{{totalPrice}}</h1>
        <button @click="add">加1</button>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vuex/dist/vuex.js"></script>
<!-- 1.引入vuex依赖 -->
<script>
    let store = new Vuex.Store({
        state: {
            counter: 555
        },
        getters: {
            totalPrice: function(state) {
                return state.counter * 10;
            }
        },
        mutations: {
            increment(state) {
                state.counter += 1;
            }
        }
    })
    let vm = new Vue({
        store,
        // 一般方式获取 vuex中 store的值
        // computed: {
        //     counter() {
        //         return this.$store.state.counter;
        //     }
        // },
        // computed: Vuex.mapState(["counter"]),
        computed: {
            totalPrice: function() {},
            ...Vuex.mapState(["counter"]),
            ...Vuex.mapGetters(["totalPrice"])
        },
        el: "#app",
        methods: {
            showStore() {
                console.log(this.$store)
            },
            add() {
                this.$store.commit("increment")
            }
        },
    })
</script>

</html>